package com.yidu.hbats.service.impl.emp;

import com.github.pagehelper.PageHelper;
import com.yidu.hbats.dao.AtsEmpCoachAthleteMapper;
import com.yidu.hbats.model.AtsEmpCoachAthlete;
import com.yidu.hbats.service.emp.AtsEmpCoachAthleteService;
import com.yidu.utils.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: hbats
 * @description: 训练项目信息实现类
 * @author: 张超
 * @create: 2019-11-01 15:19
 */
@Service
public class AtsEmpCoachAthleteServiceImpl implements AtsEmpCoachAthleteService {

    @Resource
    AtsEmpCoachAthleteMapper atsEmpCoachAthleteMapper;

    @Override
    public int saveOrUpdate(AtsEmpCoachAthlete atsEmpCoachAthlete) {
        if(StringUtils.isEmpty(atsEmpCoachAthlete.getCaId())){
            atsEmpCoachAthleteMapper.insertSelective(atsEmpCoachAthlete);
        }else{
            atsEmpCoachAthleteMapper.updateByPrimaryKeySelective(atsEmpCoachAthlete);
        }
        return 0;
    }

    @Override
    public AtsEmpCoachAthlete findById(int id) {
        return atsEmpCoachAthleteMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<AtsEmpCoachAthlete> selectAll(AtsEmpCoachAthlete atsEmpCoachAthlete, Page page) {

        PageHelper.offsetPage(page.getStart(), page.getRows());

        List<AtsEmpCoachAthlete> list = atsEmpCoachAthleteMapper.selectAll(atsEmpCoachAthlete);

        PageHelper.startPage(page.getStart(), page.getRows());
        return list;
    }

    @Override
    public int selectCount(AtsEmpCoachAthlete atsEmpCoachAthlete) {
        return atsEmpCoachAthleteMapper.selectCount(atsEmpCoachAthlete);
    }

    @Override
    public List<AtsEmpCoachAthlete> findAll(AtsEmpCoachAthlete atsEmpCoachAthlete) {
        return atsEmpCoachAthleteMapper.findAll(atsEmpCoachAthlete);
    }
}